package com.sphd.Restaurant.presenter;

import android.widget.Toast;

import com.android.volley.VolleyError;
import com.sphd.Restaurant.interfFace.VolleyCallBack;
import com.sphd.Restaurant.utils.VolleyErrorHelper;
import com.sphd.Restaurant.views.HomeView;


import org.json.JSONObject;

import java.util.List;

/**
 * Created by Hu on 2016/10/8.
 */

public class HomeP extends BasePresenter implements VolleyCallBack<JSONObject> {
    HomeView homeView;

    public HomeP(HomeView homeView) {
        this.homeView = homeView;
    }

    @Override
    public void addData(String url) {
        homeView.showdialog();
        sendJsonObjectUrl(url, this);
    }

    @Override
    public void onResponse(JSONObject jsonObject) {
        List<String> list = myJson.getCitiesList(jsonObject);
        homeView.sendList(list);
        homeView.dissmissdialog();
    }

    @Override
    public void onErrorResponse(VolleyError error) {

        Toast.makeText(context, VolleyErrorHelper.getMessage(error),Toast.LENGTH_SHORT).show();homeView.dissmissdialog();
    }
}
